<template>
  <div>
    <el-form ref="form" :rules="rules" :model="form" label-width="150px" class="layout-all form-width">
      <el-form-item prop="shop_root" label="管理员登录(请核准):">
        <el-input v-model="form.shop_root" placeholder="请输入管理员登录" />
      </el-form-item>
      <el-form-item prop="shop_name" label="店铺名称(请核准):">
        <el-input v-model="form.shop_name" placeholder="请输入店铺名称" />
      </el-form-item>
      <el-form-item prop="shop_mobile" label="店铺客服电话:">
        <el-input v-model="form.shop_mobile" placeholder="请输入店铺客服电话" />
      </el-form-item>
      <el-form-item prop="company_name" label="公司名:">
        <el-input v-model="form.company_name" placeholder="请输入公司名" />
      </el-form-item>
      <el-form-item prop="company_region_id" label="公司地址:">
        <el-input
          v-model="form.company_region_id"
          placeholder="公司地址城市ID"
        />
      </el-form-item>
      <el-form-item prop="company_address" label="详细地址:">
        <el-input v-model="form.company_address" placeholder="请输入公司地址" />
      </el-form-item>
      <el-form-item prop="company_back_address" label="对公账户所在地:">
        <el-input
          v-model="form.company_back_address"
          placeholder="请输入对公账户所在地"
        />
      </el-form-item>
      <el-form-item prop="company_back_name" label="对公账户名称:">
        <el-input
          v-model="form.company_back_name"
          placeholder="请输入对公账户名称"
        />
      </el-form-item>
      <el-form-item prop="company_back_number" label="对公账户:">
        <el-input
          v-model="form.company_back_number"
          placeholder="请输入对公账户"
        />
      </el-form-item>
      <el-form-item prop="company_back_thumb" label="对公账户电子版:">
        <img class="shop_check_img" :src="form.company_back_thumb" alt="" />
      </el-form-item>
      <el-form-item prop="license_number" label="营业执照号码:">
        <el-input
          v-model="form.license_number"
          placeholder="请输入营业执照号码"
        />
      </el-form-item>
      <el-form-item prop="license_thumb" label="营业执照电子版:">
        <img class="shop_check_img" :src="form.license_thumb" alt="" />
      </el-form-item>
      <el-form-item prop="contact_mail" label="联系人邮箱:">
        <el-input v-model="form.contact_mail" placeholder="联系人邮箱" />
      </el-form-item>
      <el-form-item prop="contact_name" label="联系人姓名:">
        <el-input v-model="form.contact_name" placeholder="请输入联系人姓名" />
      </el-form-item>
      <el-form-item prop="contact_phone:" label="联系人电话:">
        <el-input v-model="form.contact_phone" placeholder="请输联系人电话" />
      </el-form-item>
      <el-form-item prop="contact_sex" label="联系人性别:">
        <el-select v-model="form.contact_sex" placeholder="请输入联系人性别" >
        <el-option
            v-for="item in sex_options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item prop="linked_bank_name" label="结算银行名称:">
        <el-input
          v-model="form.linked_bank_name"
          placeholder="请输入结算银行名称"
        />
      </el-form-item>
      <el-form-item prop="linked_bank_address" label="结算银行开户行:">
        <el-input
          v-model="form.linked_bank_address"
          placeholder="请输入结算银行卡号"
        />
        </el-form-item>
      <el-form-item prop="linked_bank_number" label="结算银行卡号:">
        <el-input
          v-model="form.linked_bank_number"
          placeholder="请输入结算银行卡号"
        />
      </el-form-item>
<el-form-item prop="shop_cate_id" label="经营类目:">
       <el-select v-model="shop_cate_id" multiple placeholder="" @change="change_cate">
        <el-option
          v-for="item in cate"
          :key="item.id"
          :label="item.title"
          :value-key="item.id"
          :value="item.id">
        </el-option>
      </el-select>
</el-form-item>
      <el-form-item>
        <el-button type="info" size="mini"  @click="bk()" >返回</el-button>
        <el-button type="success" size="mini" v-if="form.status<2" @click="handle_status()"
          >通过</el-button
        >
        <el-button type="danger" size="mini" v-if="form.status<2" @click="dialog_visible = true"
          >拒绝</el-button
        >
      </el-form-item>
    </el-form>
    <el-dialog title="拒绝申请" :visible.sync="dialog_visible" :width="isMobile()?'80%':'30%'">
      <el-form
        ref="stock_form"
        :rules="rules"
        :model="form"
        label-width="100px"
      >
        <el-form-item prop="remark" label="拒绝原因:">
          <el-input
            v-model="form.remark"
            type="textarea"
            :rows="3"
            placeholder="请输入拒绝原因"
          />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialog_visible = false">取 消</el-button>
        <el-button type="primary" @click="refuse()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
    name:'shop_check_form',
  data() {
    return {
      id: 0,
      is_change: undefined,
      dialog_visible: false,
      cate: [],
      shop_cate_id: [],
      sex_options: [
        { value: 0, label: '未知' },
        { value: 1, label: '男' },
        { value: 2, label: '女' }
      ],
      form: {
        company_address: "", //地址
        company_back_address: "", //对公账户所在地
        company_back_name: "", //对公账户名称
        company_back_number: "", //对公账户
        company_back_thumb: "", //对公账户电子版
        company_name: "", //公司名
        company_region_id: "", //公司地址城市ID
        contact_name: "", //联系人姓名
        contact_mail: "", //联系人邮箱
        contact_phone: "", //联系人电话
        contact_sex: "", //联系人性别
        license_number: "", //营业执照号码
        license_thumb: "", //营业执照电子版
        linked_bank_address: "", //结算银行名称
        linked_bank_number: "", //结算银行卡号
        shop_cate_id: [], //商铺类目ID
        shop_mobile: "", //店铺客服电话
        shop_name: "", //店铺名称
        shop_root: "", //店铺登录名
        shop_type: "", //店铺类型
        status: "", //申请状态
      },
      rules: {},
    };
  },
  mounted() {
    this.id = (this.$route.params && this.$route.params.id)||0
    this.$setTagsViewTitle(this.id)
    this.init_into();
  },
  methods: {
    bk() {
      this.$back(this.is_change?0:1);
    },
    init_into() {
      this.get("/admin/ShopApply/info?id=" + this.id, this.form, "POST").then(
        (e) => {
          const tpl = e.info.tpl;
          this.cate = e.cate;
          console.log(e);
          this.form = tpl;
          for(var i in this.form.shop_cate_id){
            this.shop_cate_id[i]=Number(this.form.shop_cate_id[i])
          }
        }
      );
    },
    //拒绝申请
    refuse() {
      this.done(3)
    },
    change_cate(e) {
      console.log(e)
      console.log(this.form.shop_cate_id)
    },
    //通过拒绝按钮
    handle_status() {
      this.$msg_confirm_show("确认通过此商铺审核?").then((e) => {
            this.done(2)
        })
    },
    done(status){
      if(status==3&&this.form.remark==''){
        this.$message({
          type: 'success',
          message: '请填写理由'
        })
        return
      }
      this.form.status=status
      this.form.shop_cate_id=this.shop_cate_id
        this.get("/admin/ShopApply/save", this.form, "POST").then(
        (e) => {
          console.log(e);
          this.dialog_visible=false
          this.is_change=true
        }
      ).catch((e) => {this.form.status=1})
    }
  }
};
</script>

<style>
.layout-all {
  margin: 10px;
}
.shop_check_img {
  width: 100px;
  height: 100px;
}
</style>
